package day10;

import java.io.*;
import java.net.Socket;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class ObjectThread extends Thread {
    private final Socket s;
    private Map<String,String> m=new HashMap<>();
    public ObjectThread(Socket s){
        this.s=s;
        m.put("zuigao","胡冰");
        m.put("zuiai","laoliu");
        m.put("最帅","阿豪");
        m.put("ugly","王凯宣");
        m.put("renshu","33");
        m.put("now",String.valueOf(new Date()));
    }

    @Override
    public void run() {
        try {
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            ObjectOutputStream oout=new ObjectOutputStream(out);
            ObjectInputStream oin=new ObjectInputStream(in);
            oout.writeObject(m);
            oout.flush();
            Object o = oin.readObject();
            System.out.println("从"+s+"收到了："+o);

        } catch (Exception e) {
            //e.printStackTrace();
            System.out.println(e);
        }finally {
            try {
                s.close();
            } catch (Exception e) {
                //e.printStackTrace();
            }
        }

    }
}
